home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / Programmer's Digest 1.0.sit / The Programmers Digest™ 1.0.rsrc / TEXT_135.txt < prev    next >
Text File  |  1998-11-11  |  9KB  |  227 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.                                                 Introduction into COBOL
  20.  
  21.  
  22. Cobol is probably one of the most unused programming Languages at this time. It is mainly used in companies, that want to change their old databases to newer ones because, Cobol is compatible to nothing :). A list of Compilers for the Mac and PC is in the appendix. 
  23.  
  24. In Cobol there are 4 Divisions, where the user has to input some information about the Computer he uses, where variables get declared, etc.
  25.  
  26. 1.) The Identification Division:
  27. an example for an identification division is (the blue words are non-changable words):
  28. IDENTIFICATION DIVISION.
  29. PROGRAM-ID. TEST.
  30.  
  31. The first line just names the Division. In the second line stands the program's name. In that case the name is "test". Note: In all divisions (and just in divisions), there's a "." after every command.
  32.  
  33.  
  34. 2.) The Environment Division:
  35. an example for an environment division is (the blue words are non-changable words):
  36. ENVIRONMENT DIVISION.
  37. CONFIGURATION SECTION.
  38. SPECIAL-NAMES.
  39. TERMINAL IS  T.
  40. DECIMAL-POINT IS COMMA.
  41.  
  42. the Environment Division does subdivide into sections. For this time we just need the Configuration Section. Here we configure how our terminal is named, and what char you want to use as a decimal point. You need the terminal name for in- and output (like "accept variable from T").
  43.  
  44.  
  45. 3.) The Data Division:
  46. an example for a data division is (the blue words are non-changable words):
  47. DATA DIVISION.
  48. WORKING-STORAGE SECTION.
  49. 01 TEXT PIC X(7).
  50. 01 NUMBER1 PIC 99.
  51. 01 NUMBER2 PIC 9(15).
  52.  
  53. Here we define our variables. We don't write "int x" or "dim x as integer" in Cobol, like we do it in C and other programming languages. Here every variable has a number (in our example the number is 01). That number can be any number from 01 to 65. It‚Äòs better to define every variable with 01, so we wont lose overview. After this number, there comes the variable-name. Next to the name, stands the word "pic". This doesn‚Äòt mean picture, and for basic programming we must not know, what it means. Then we write even a "X" or a "9". A "X" means, that the variable is alphanumeric, a "9" means that it is numeric. Then comes the number of places we wan‚Äòt to use for the variable. "XXXXXX‚Äú means the same like "X(6)". Here we have three variables with the number 01. The first one is named TEXT and has seven alphanumeric places. The second  one is named NUMBER1 and has two numeric places. The third one is named NUMBER2 and has 15 numeric places.
  54. Note: Alphanumeric means, that the user can input letters and numbers. Numeric means, only to input numbers.
  55.  
  56.  
  57. 4.) The Procedure Division:
  58. an example for a procedure division is (the blue words are non-changable words):
  59. PROCEDURE DIVISION.
  60. MAIN.
  61.  
  62. The word "main" is the name of our first sub-program. 
  63. Note: Often we don't need Sub-programs in Cobol. So the Sub-program "main" contains the whole source.
  64.  
  65.  
  66. 5.) Basic Commands:
  67.  
  68. 5.1.) In- and Output.
  69.  
  70. For inputting a variable use: Accept <variable name> from <Terminal name>
  71. For outputting a variable use: Display <variable name> upon <Terminal name>
  72. For outputting a text use: Display <"Text here"> upon <Terminal name>
  73. Note: We can't input variables with a default prompt.
  74.  
  75. 5.2.) Mathematics Operations:
  76.  
  77. For adding two variables use: Add <variable1> to <variable2> giving <variable>.
  78. For subtracting two variables use: Subtract <variable1> from <variable2> giving <variable>
  79. For multiplying two variables use: Multiply <variable1>  by <variable2> giving <variable>
  80. For dividing two variables use: Divide <variable1> into <variable2> giving <variable>
  81. If you have to compute more than two variables use: Compute <variable> = 15668*2+1
  82. Note: We can sure, also compute some numbers like: Divide 17 into 13 giving x. The "giving" option mustn‚Äòt be used. If we just write Add x to y  the result will be stored in the variable x.
  83.  
  84. 5.3) Loops:
  85.  
  86. In Cobol there‚Äòs just one kind of loop, we need for starting. It is:
  87. Perform until <Condition>. 
  88.  
  89. An example for a loop is:
  90. Perform until x = 10
  91.  Display x upon t
  92.  x = x + 1
  93. end-perform
  94.  
  95. Note: In Cobol we must tell the Compiler, when the loop is over. In a perform loop we are doing this with an "end-perfom".
  96.  
  97. 5.4.) Query‚Äòs:
  98.  
  99. There is only one query we need at this time. The correct syntax is:
  100. If <Condition> then
  101.  blah
  102.  blah
  103. else
  104.  blah
  105.  blah
  106. end-if
  107.  
  108. Note: A "if" must also end with an "end-if".
  109.  
  110.  
  111. 6.) Now we know the Basic Cobol-command‚Äòs. Let‚Äòs write our first program: a calculator (what else ;):
  112.  
  113.        IDENTIFICATION DIVISION.
  114.        PROGRAM-ID.  CALC.
  115.        ENVIRONMENT DIVISION.
  116.        CONFIGURATION SECTION.
  117.        SPECIAL-NAMES.
  118.            TERMINAL IS T.
  119.        DATA DIVISION.
  120.        WORKING-STORAGE SECTION.
  121.        01 NUMBER1 PIC 9(4).
  122.        01 NUMBER2 PIC 9(4).
  123.        01 OPERATOR PIC X.
  124.        01 END? PIC X.
  125.        01 RESULT PIC 9(9).
  126.        PROCEDURE DIVISION.
  127.        MAIN.
  128.            PERFORM UNTIL END? NOT= "Y" OR "y"
  129.            DISPLAY "PLEASE INPUT THE FIRST NUMBER:" UPON T
  130.            ACCEPT NUMBER1 ONE FROM T
  131.            DISPLAY "PLEASE INPUT THE OPERATOR (*, -, +, /):"
  132.            ACCEPT OPERATOR FROM T
  133.            DISPLAY "PLEASE INPUT THE SECOND NUMBER" UPON T
  134.            IF OPERATOR = "+" THEN
  135.              ADD ZAHL1 TO ZAHL2 GIVING RESULT
  136.            END IF
  137.            IF OPERATOR = "-" THEN
  138.             SUBTRACT NUMBER2 FROM NUMBER1 GIVING RESULT
  139.            END IF
  140.            IF OPERATOR = "*" THEN
  141.             MULTIPLY NUMBER1 BY NUMBER2 GIVING RESULT
  142.            END IF
  143.            IF OPERATOR = "/" THEN
  144.             DIVIDE NUMBER2 INTO NUMBER1 GIVING RESULT.
  145.            END IF
  146.            DISPLAY "THE RESULT OF" NUMBER1 " " OPERATOR " " NUMBER2 " = " RESULT
  147.            DISPLAY ""
  148.            DISPLAY "AGAIN? (Y/N)"
  149.            INPUT END?
  150.           END-PERFORM
  151.           STOP RUN.
  152.  
  153.  
  154. 7.) The Appendix:
  155.  
  156. Now we know some basic Cobol-commands. I don‚Äòt know if I will write more about Cobol, cause my opinion is that you won't need it very often :). Anyway, if you wan't to tell me something (like doing a second section :)., mail to: bern@pantucek.vienna.at. btw: I even know some Contact addresses, where Cobol-compilers are viable.
  157.  
  158. 7.1) Where can I get a COBOL compiler ?
  159.  
  160.     7.1.1 for DOS, Windows or OS/2 ?
  161.                                 Acu, CA, Liant, MBP and Micro Focus all produce compilers for one
  162.         or more of these environments.  Microsoft used to re-badge the
  163.         Micro Focus compiler, but not any more.
  164.  
  165.     7.1.2 for Windows/NT ?
  166.                                 Micro Focus has a COBOL 32-bit SDK available for Windows/NT.
  167.  
  168.     7.1.3 for UNIX ?
  169.                                 Acu, Liant and Micro Focus have products available across
  170.         a large number of UNIX platforms.  Some OEMs re-badge and/or
  171.         reengineer these products for their own systems, too.
  172.  
  173.     7.1.4 for the Macintosh ?
  174.                                 Micro Focus and Liant produce a COBOL development system
  175.         for the Mac running A/UX.
  176.  
  177.         Micro Focus have also announced that they will be releasing
  178.         a product on MacOS.  There are currently no dates for release.
  179.  
  180.  
  181.     7.1.5 for other environments ?
  182.                                 Most major vendors have their own COBOL implementation, or
  183.         have someone else's ported to their platform(s).  There are
  184.         quite a few available for CP/M and MP/M, and one is even
  185.         rumoured to have been available for the PERQ workstation.
  186.  
  187. 7.2) Is there a free COBOL compiler ?
  188.                 Just for the record, no COBOL tools are listed in the Catalog
  189.     of compilers, interpreters, and other language tools posted to
  190.     comp.compilers and comp.lang.misc.
  191.  
  192.     However, two books in the book list come with a COBOL compiler.  See
  193.     section 10 for details.
  194.  
  195.  
  196.     7.2.1 for DOS, Windows or OS/2.
  197.                                 There is a freely available COBOL compiler for DOS.  It can be
  198.         found on many archive sites, named cobol650.zip.  The sources
  199.         are not available, however.  Have a read through Section 8
  200.         before you start.
  201.                                 Also, it may be possible to run the freely available CP/M
  202.         compiler (see 4.5) under a freely available CP/M emulator.
  203.  
  204.     7.2.2 for Windows/NT ?
  205.                                 The CP/M compiler/emulator combination should work here, too.
  206.  
  207.     7.2.3 for UNIX ?
  208.                                 There are no well-documented examples of a freely available COBOL
  209.         compiler for UNIX.
  210.  
  211.         COBOL 6.50 might run under a UNIX emulation of a DOS system,
  212.         however.  (For example, Sun's WABI for the Sparc and Intel
  213.         platforms, or dosemu under Linux.)
  214.  
  215.         The CP/M compiler (see 4.5) should run under a CP/M emulator
  216.         for UNIX in a similar fashion.
  217.  
  218.     7.2.4 for the Macintosh ?
  219.                                         Not that I know of.
  220.  
  221. 7.2.5 for other environments ?
  222.                                     There is a freely available CP/M COBOL compiler/interpreter
  223.          (NPS Micro COBOL).  This is available via anonymous FTP
  224.          from oak.oakland.edu in /pub/cpm/cobol.
  225.  
  226. Article by: 4E71
  227. Edited by: ZiffDuck